# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

users = YAML.load_file(File.join(Rails.root, 'db', 'users.yml')).map{|u| u.deep_symbolize_keys }
users.each do |user|
  u = User.create_with(user.slice(:password, :role, :name)).find_or_create_by!(email: user[:email])
  u.update(confirmed_at: Time.now) unless u.confirmed_at
end

site_configs = YAML.load_file(File.join(Rails.root, 'db', 'site_configs.yml'))
site_configs.each do |key, value|
  site_config = SiteConfig.create_with(value: value).find_or_create_by!(key: key)
  site_config.update(value: value)
end
